
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.ibatis.session.SqlSession;

import com.spark.dao.SessionFactory;

public class AccountsImport {

	/**
	 * @param args
	 * @throws IOException 
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {
		SqlSession sqlSession = SessionFactory.getSession();
		try {
			
			List lines = FileUtils.readLines(new File("data.csv"), "UTF-8");
			Iterator it = lines.iterator();
			while(it.hasNext()){
				String line = (String)it.next();
				String[] strs = line.split(",");
				Map map = new HashMap();
				map.put("ACCOUNT_CODE", strs[0].trim());
				map.put("SET_OF_BOOKS_ID", 1);
				map.put("ACCOUNT_NAME", strs[1].trim());
				map.put("COMPANY_ID", 1);
				map.put("ACCOUNT_TYPE", "P");
				map.put("SUMMARY_FLAG", "N");
				map.put("ENABLED_FLAG", "Y");
				sqlSession.insert("gld_accounts.insert", map);
			}
			
		} finally {
			SessionFactory.closeSession(sqlSession);
		}

	}

}
